package com.ycw.service.imp.WJK;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ycw.bean.Admin;
import com.ycw.bean.Comments;
import com.ycw.bean.Funding;
import com.ycw.bean.Projects;
import com.ycw.bean.Users;
import com.ycw.dao.AdminMapper;
import com.ycw.dao.CommentsMapper;
import com.ycw.dao.FundingMapper;
import com.ycw.dao.ProjectsMapper;
import com.ycw.dao.ProjectsTypeMapper;
import com.ycw.dao.UsersMapper;
import com.ycw.service.WJK.WeiService;
@Service
public class WeiServiceImpl implements WeiService {

	@Autowired
	UsersMapper usersMapper;
	@Autowired
	AdminMapper adminMapper;
	@Autowired
	ProjectsMapper projectsMapper;
	@Autowired
	ProjectsTypeMapper projectsTypeMapper;
	@Autowired
	CommentsMapper commentsMapper;
	@Autowired
	FundingMapper fundingMapper;
	
	@Override
	public boolean checkUsers(String usEmail) {
		Users user=new Users();
		user.setUsEmail(usEmail);
		user=usersMapper.selectOne(user);
		if (user!=null) {
			return true;
		}else {
			return false;
		}
		
	}

	@Override
	public Users usersLogin(Users users) {
		
		users=usersMapper.selectOne(users);
		return users;
	}

	@Override
	public Admin adminLogin(Admin admin) {
		admin=adminMapper.selectOne(admin);
		return admin;
	}

	@Override
	public List<Projects> getAllProjects() {
		List<Projects> list=projectsMapper.getAllProjects();
		return list;
	}

	@Override
	public Map<String, Object> getProjectDetaile(Integer psId, Integer pn) {
		Map<String , Object> map=new HashMap<String, Object>();
		Projects projects=projectsMapper.getProjectById(psId);
		map.put("projects", projects);
		if (projects.getPsType()!=0&&projects.getPsType()!=5) {
			PageHelper.startPage(pn,5);
			List<Comments> list=commentsMapper.getALLCommentsByPsId(psId);
			PageInfo page=new PageInfo(list);
			map.put("page", page);
			Double progress=projects.getPsGetmoney()/projects.getPsMoney();
			map.put("progress", progress);
			
			List<Funding> list2=fundingMapper.getALLFundingByPsId(psId);
			PageInfo page2=new PageInfo(list2);
			map.put("page2", page2);
			
		}
		return map;
	}
}
